package com.qf.controller;

import com.qf.model.StudentVO;
import com.qf.service.StudentSerivce;
import com.qf.service.StudentService2;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author GUOFUCHENG
 * @date 2025/8/14
 * @desc
 */
@RestController
public class StudentController2 {

    @Autowired
    private StudentService2 studentSerivce2;

    // 查询所有学生信息以及关联的班级信息
    @PostMapping("/class")
    public R findAllStuAndCal() {
        List<StudentVO> list = studentSerivce2.findAllStuAndCal();
        return R.success(list);
    }

    //一对多
    // 查询一个学生信息以及所学习的所有学科信息
    @PostMapping("/subject/{id}")
    public R findStuAndSubInfo(@PathVariable int id) {
        List<StudentVO> studentVOList = studentSerivce2.findStuAndSubInfo(id);
        return R.success(studentVOList);
    }

    // 需求: 查询一个学生信息以及所学习的所有学科信息,以及每个学科关联的老师信息

    @PostMapping("/teacher/{id}")
    public R findStuAndSubAndTeaInfo(@PathVariable int id) {
        List<StudentVO> studentVOS = studentSerivce2.findStuAndSubAndTeaInfo(id);
        return R.success(studentVOS);
    }



    // 业务层拆解多表联查
// 需求:查询学生信息以及关联的教室信息

    @PostMapping("class/v2")
    public R findAllStudentAndClassroom(){
      List<StudentVO> list = studentSerivce2.findAllStudentAndClassroomV2();
        System.out.println("list = " + list);
        return R.success(list);
    }

    // 需求:查询一个学生信息以及所学习的所有学科信息
    @PostMapping("subject/v2/{id}")
    public R findStudentAndAllSubjectByStuidV2(@PathVariable int id){
        StudentVO studentVO= studentSerivce2.findStudentAndAllSubjectByStuidV2(id);
        return R.success(studentVO);
    }
}
